import { Vec3 } from "cc";
import { SmoothDamper, Vec3_closeTo } from "../Common/Math";
import { IVCam } from "../Datas/IVCam";
import { CameraHandler } from "./CameraHandler";

let __worldPos = new Vec3();
let __targetPos = new Vec3();
export class TransposerHandler extends CameraHandler<IVCam> {
    private _smoothDamper: SmoothDamper = new SmoothDamper();

    public updateCamera(deltaTime: number) {
        let vcam = this._vcam;
        if (vcam.follow == null) return;

        let transposer = vcam.body.transposer;
        Vec3.add(__targetPos, vcam.follow.worldPosition, transposer.followOffset);
        this._smoothDamper.Vec3_smoothDamp(__worldPos, vcam.node.worldPosition, __targetPos, transposer.followDamping, deltaTime);

        if (!Vec3_closeTo(__worldPos, vcam.node.worldPosition)) {
            vcam.node.worldPosition = __worldPos;
        }
    }
}